<template>
    <div>
        <!-- 顶部滑动条 -->
        <div id="slider" class="mui-slider">
				<div  id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll" >
						<a @click="getphotos(val.id)" :class="['mui-control-item',val.id==0 ? 'mui-active':'']" v-for="val in photolist" :key="val.id"  data-wid="tab-top-subpage-1.html">
							{{val.title}}
						</a>
					</div>
				</div>
			</div>
        <ul class="photo-list">
            <router-link v-for="(item,i) in photolist12" :key="i" :to="`/home/photoinfo/${item.id}`" tag="li">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-body">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>
<script>
import mui from '../../lib/mui/dist/js/mui.min.js'
import axios from 'axios'
import {Toast} from 'mint-ui'
    export default {
        data(){
            return {
                photolist:[],
                photolist12:[],
                // id:[]
            }
        },
         created() {
            this.getAllCategory()
            // 默认进入页面，就主动请求所有图片列表
            this.getphotos(0)
        },
        mounted() {//当组件中的dom结构被渲染好并放到页面中后，会执行这个钩子函数
        // 如果要操作元素最好在mounted里面，因为这时候的dom元素是最新的
            // 初始化滑动组件
            mui('.mui-scroll-wrapper').scroll({
	                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
       
        methods:{
            getAllCategory(){
                axios({
                    method:'get',
                    baseURL:'http://www.liulongbin.top:3005/',
                    url:'api/getimgcategory'
                }).then(res=>{
                    if(res.data.status===0){
                        res.data.message.unshift({title:'全部',id:0})
                        this.photolist=res.data.message
                        // this.id.push(res.data.message.id)
                    }else{
                        Toast("获取数据失败")
                    }
                })
            },
            getphotos(cateid){
                axios({
                    method:'get',
                    url:`http://www.liulongbin.top:3005/api/getimages/${cateid}`
                }).then(res=>{
                    if(res.data.status===0){
                        this.photolist12=res.data.message
                    }
                })
            }
        }
    }
</script>
<style lang="scss" scoped>
.mint-header{
    position:relative;
    z-index: 999;
};
.photo-list{
    list-style: none;
    margin: 0;
    padding: 10px;
    li{
        background-color: #ccc;
        text-align: center;
        margin-bottom: 15px;
        box-shadow: 0 0 9px #999;
        position: relative;
        img{width: 100%;
           margin-bottom: -10px;
        };
        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        };
        .info{
            color: white;
            text-align: left;
            position: absolute;
            bottom: 0;
            background-color:rgba(0,0,0,0.4);
            max-height: 80px;
            .info-title{
                font-size: 14px;
            }
            .info-body{
                font-size: 9px;
            }
        }
        
    }
}
</style>
